package cl.tinet.finalexam.model;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * 
 * Model class user. Links the BD with Java
 * 
 * @author ivillacu
 */

@Entity
@Table(name="usuarios")
public class UserModel implements Serializable {

    /**
     * Serial version of the class.
     */
    private static final long serialVersionUID = 1L;

    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy="userEntity")
    private Collection<ReserveModel> reservesCollections;
    /**
     * Link username from BD.
     */
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "userID")
    private int userID;
    
    @Column(name = "username")
    private String username;

    /**
     * Link Name from BD.
     */
    @Column(name = "nombre")
    private String name;

    /**
     * Link Last Name from BD.
     */
    @Column(name = "apellido")
    private String lastName;

    /**
     * Link password from BD.
     */
    @Column(name = "password")
    private String password;

    /**
     * Link user type from BD.
     */
    @Column(name = "tipo")
    private int type;

    public UserModel(){
        
    }
    

    /**
     * TODO doc information expected for UserModel constructor.
     *
     * @param userID
     * @param username
     * @param name
     * @param lastName
     * @param password
     * @param type
     */
    public UserModel(int userID, String username, String name,
            String lastName, String password, int type) {
        super();
        this.userID = userID;
        this.username = username;
        this.name = name;
        this.lastName = lastName;
        this.password = password;
        this.type = type;
    }


    /**
     * Allows to get the userID attribute value.
     * @return the userID value.
     */
    public int getUserID() {
        return userID;
    }


    /**
     * Allows to set the userID attribute value.
     *
     * @param userID new value for userID attribute.
     */
    public void setUserID(int userID) {
        this.userID = userID;
    }


    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return Integer.valueOf(this.password);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object obj) {
        boolean isEqual = false;

        if (this.username.equals(((UserModel) obj).username)) {
            isEqual = true;
        }
        return isEqual;
    }
    
    

    /**
     * Allows to get the reservesCollections attribute value.
     * @return the reservesCollections value.
     */
    public Collection<ReserveModel> getReservesCollections() {
        return reservesCollections;
    }
    /**
     * Allows to set the reservesCollections attribute value.
     *
     * @param reservesCollections new value for reservesCollections attribute.
     */
    public void setReservesCollections(Collection<ReserveModel> reservesCollections) {
        this.reservesCollections = reservesCollections;
    }
    /**
     * 
     * Getter for username.
     * 
     * @return Username of the user
     */
    public String getUsername() {
        return username;
    }

    /**
     * 
     * Setter for the username
     * 
     * @param username
     *            username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * 
     * Getter for name.
     * 
     * @return Name of the user
     */
    public String getName() {
        return name;
    }
    
    /**
     * 
     * Setter for the name
     * 
     * @param username
     *            name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    
    /**
     * 
     * Getter for Last Name.
     * 
     * @return Last name of the user
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * 
     * Setter for the Last Name
     * 
     * @param username
     *            lastname to set
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * 
     * Getter for Password.
     * 
     * @return password of the user
     */
    public String getPassword() {
        return password;
    }

    /**
     * 
     * Setter for the password
     * 
     * @param username
     *            password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }
    /**
     * 
     * Getter for type.
     * 
     * @return type of the user
     */
    public int getType() {
        return type;
    }

    /**
     * 
     * Setter for the type
     * 
     * @param username
     *            type to set
     */
    public void setType(int type) {
        this.type = type;
    }
    
    

}
